package com.webmuseum.client;

import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.Widget;

public class UIMultiContainer extends UIContainer 
{
	
	public UIMultiContainer(Widget aWidget)
	{
		super(aWidget);
		PushButton addButton = new PushButton();
		addButton.setText("+");
		addButton.addClickHandler(new CloneHandler(this, aWidget));
		int i = 0;
		setWidget(i, mIndex.CTRL_INDEX.ordinal(), addButton);
		//setWidget(i, mIndex.WIDGET_INDEX.ordinal(), aWidget);
	}
	
	public void addRemovableWidget(Widget aWidget)
	{
		PushButton remButton = new PushButton();
		remButton.setText("-");
		remButton.addClickHandler(new DecloneHandler(this, aWidget));
		int index = getRowCount();
		setWidget(index, mIndex.CTRL_INDEX.ordinal(), remButton);
		setWidget(index, mIndex.WIDGET_INDEX.ordinal(), aWidget);	
	}

	public void removeRemovableWidget(Widget mCloneWidget) 
	{
		for(int i=0; i < getRowCount(); ++i)
		{
			if(getWidget(i, mIndex.WIDGET_INDEX.ordinal()).equals(mCloneWidget))
			{
				removeRow(i);
				break;
			}
		}
	}
	
	public UIMultiContainer clone()
	{
		UIMultiContainer r = new UIMultiContainer(CloneManager.getInstance().cloneWidget(getWidget(0, mIndex.WIDGET_INDEX.ordinal())));
		return r;
	}
	
}
